# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >

_realname=numexpr
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-$_realname" "${MINGW_PACKAGE_PREFIX}-python3-$_realname")
pkgver=2.4.6
pkgrel=1
pkgdesc="Fast numerical array expression evaluator for Python, NumPy, PyTables, pandas. (mingw-w64)"
arch=('any')
url="https://github.com/pydata/numexpr"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-numpy"
             "${MINGW_PACKAGE_PREFIX}-python3-numpy"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-gcc")
source=("${_realname}-${pkgver}.tar.gz"::https://github.com/pydata/numexpr/archive/v${pkgver}.tar.gz)
sha256sums=('2681faf55a3f19ba4424cc3d6f0a10610ebd49f029f8453f0ba64dd5c0fe4e0f')

prepare() {
  cp -a ${_realname}-${pkgver} $_realname-py2-${pkgver}
  cp -a ${_realname}-${pkgver} $_realname-py3-${pkgver}

  cd ${_realname}-py2-${pkgver}
  sed -e "s|#![ ]*/usr/bin/python$|#!/usr/bin/python2|" \
    -e "s|#![ ]*/usr/bin/env python$|#!/usr/bin/env python2|" \
    -e "s|#![ ]*/bin/env python$|#!/usr/bin/env python2|" \
    -i $(find . -name '*.py')
}

build() {
  # build for python2
  cd ${srcdir}/${_realname}-py2-${pkgver}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py build

  # build for python3
  cd ${srcdir}/${_realname}-py3-${pkgver}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py build
}

package_python2-numexpr() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2-numpy")

  cd ${_realname}-py2-${pkgver}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --skip-build \
  --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1

  install -Dm644 LICENSE.txt \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE.txt"
}

package_python3-numexpr() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3-numpy")

  cd ${_realname}-py3-${pkgver}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --skip-build \
  --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1

  install -Dm644 LICENSE.txt \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE.txt"
}

package_mingw-w64-i686-python2-numexpr() {
  package_python2-numexpr
}

package_mingw-w64-i686-python3-numexpr() {
  package_python3-numexpr
}

package_mingw-w64-x86_64-python2-numexpr() {
  package_python2-numexpr
}

package_mingw-w64-x86_64-python3-numexpr() {
  package_python3-numexpr
}
